<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px">
    <el-col>
      <span>{{ obj.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ obj.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="$emit('additem',obj)">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="isshow" @click.native="$emit('editDept',obj)">查看子部门</el-dropdown-item>
              <el-dropdown-item v-if="isshow" @click.native="onDel()">删除子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { deletedepartments } from '@/api/departments'
export default {
  props: {

    obj: {
      type: Object,
      required: true
    },
    isshow: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {

    }
  },
  created() {

  },

  methods: {
    onDel() {
      this.$confirm('此操作将永久删除该部门, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await deletedepartments(this.obj.id)
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.el-row{
  width: 100%;
}

// ::v-deep el-col-24 {
//   width: 10px;
//   overflow: hidden;
// }
</style>
